package com.pension.servlet.room;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pension.model.dao.RoomDao;
import com.pension.model.dto.Room;


@WebServlet("/room/register.action")
public class RoomRegisterServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		String roomnumber = req.getParameter("roomnumber");
		String roomname = req.getParameter("roomname");
		String roomtype = req.getParameter("roomtype");
		String maxpeople = req.getParameter("maxpeople");
		String acreagesize = req.getParameter("acreagesize");
		String priceroom = req.getParameter("priceroom");
		
		Room room = new Room();
		room.setRoomNumber(Integer.parseInt(roomnumber));
		room.setRoomName(roomname);
		room.setRoomType(roomtype);
		room.setMaxPeople(Integer.parseInt(maxpeople));
		room.setAcreageSize(Integer.parseInt(acreagesize));
		room.setPriceRoom(Integer.parseInt(priceroom));
		
		

		RoomDao dao = new RoomDao();
		dao.insertRoom(room);
		
		// 등록 후 목록 화면으로 이동
		//HttpResponse.sendRedirect : 지정된 경로로 요청을 재전송
		resp.sendRedirect("/pension/room/admin.action");
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}






